package main

import (
	"encoding/json"
	"fmt"
	"os"
)

type User struct {
	UserName string
	NickName string `json:"nickname"`
	Email    string
}

func main() {
	user := &User{
		UserName: "Jack",
		NickName: "Ma",
		Email:    "xxxxx@qq.com",
	}

	//将json序列化为字节
	data, err := json.Marshal(user)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(string(data))

	fp, _ := os.Create("cp6_file/json/json_write.json")
	defer fp.Close()
	fp.Write(data)
}
